﻿using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using NetProtocol.Client;
using NetProtocol.POD;
using System.Collections.Generic;

namespace IQIGame.Onigao.GamePlay
{
    public class PlayerModule : Singleton<PlayerModule>, CNetPlayer
    {
        private PlayerModule() { }
        public static CNetPlayer NetCore => Instance;


        public void InitModule(PlayerPOD playerPOD)
        {
            GameDataCenter.PlayerData.pid = playerPOD.pid;
            GameDataCenter.PlayerData.uid = playerPOD.uid;
            GameDataCenter.PlayerData.guid = playerPOD.guid;
            GameDataCenter.PlayerData.openId = playerPOD.openId;
            GameDataCenter.PlayerData.roleCid = playerPOD.roleCid;
            GameDataCenter.PlayerData.createTime = playerPOD.createTime;
            GameDataCenter.PlayerData.areaId = playerPOD.areaId;
            GameDataCenter.PlayerData.gameServerId = playerPOD.gameServerId;
            GameDataCenter.PlayerData.sdkName = playerPOD.sdkName;
            GameDataCenter.PlayerData.channelNo = playerPOD.channelNo;
            GameDataCenter.PlayerData.level = playerPOD.level;
            GameDataCenter.PlayerData.exp = playerPOD.exp;
            GameDataCenter.PlayerData.playerName = playerPOD.playerName;
            GameDataCenter.PlayerData.avatar = playerPOD.avatar;
            GameDataCenter.PlayerData.avatarFrame = playerPOD.avatarFrame;
            GameDataCenter.PlayerData.intro = playerPOD.intro;
            GameDataCenter.PlayerData.title = playerPOD.title;
            GameDataCenter.PlayerData.kanban = playerPOD.kanban;
            GameDataCenter.PlayerData.payPoint = playerPOD.payPoint;
            GameDataCenter.PlayerData.sumPay = playerPOD.sumPay;
            GameDataCenter.PlayerData.functionTypes = playerPOD.functionTypes;
            GameDataCenter.PlayerData.playerParams = playerPOD.playerParams;
        }

        public void ClearModule()
        {

        }

        private void UpdatePlayerInfo(UpdatePlayerInfoPOD podUpdate)
        {
            var playerData = GameDataCenter.PlayerData;
            switch (podUpdate.key)
            {
                case NetProtocol.Enum.PlayerInfoKey.Exp:
                    playerData.exp = podUpdate.intValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.Level:
                    playerData.level = podUpdate.intValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.PayPoint:
                    playerData.payPoint = podUpdate.intValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.Name:
                    playerData.playerName = podUpdate.stringValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.Avatar:
                    playerData.avatar = podUpdate.intValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.AvatarFrame:
                    playerData.avatarFrame = podUpdate.intValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.Title:
                    playerData.title = podUpdate.intValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.Intro:
                    playerData.intro = podUpdate.stringValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.SumPay:
                    playerData.sumPay = podUpdate.intValue;
                    break;
                case NetProtocol.Enum.PlayerInfoKey.Kanban:
                    playerData.kanban = podUpdate.intValue;
                    break;
                default:
                    break;
            }
        }

        public HeroData GetPlayerAvatarHeroData()
        {
            var playerData = GameDataCenter.PlayerData;
            var defaultFormation = playerData.formation.defaultFormationData;
            playerData.hero.FindHeroDataByCid(defaultFormation.captainHeroCid, out var heroData);
            return heroData;
        }

        void CNetPlayer.SC_notifyFunctionTypeOpen(ISession session, int functionTypeId)
        {
            GameDataCenter.PlayerData.functionTypes.Add(functionTypeId);
            FunctionModule.Instance.JugdeShowingWhenFunctionTypeOn(functionTypeId);
        }

        void CNetPlayer.SC_notifyUnlockEvent(ISession session, int eventCid)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyEnergyRecovery(ISession session, int energy, int nextRecoveryEnergyTime)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_updatePlayerGlobalBuff(ISession session, List<GlobalBuffPOD> globalBuffs)
        {
            ////throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyUnLockAvatar(ISession session, int avatarId, bool remove)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyReadPoint(ISession session, Dictionary<int, bool> readPoint)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyUpdatePlayerParams(ISession session, int paramID, int value)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyEffectNotice(ISession session, int effectType, List<int> effectParams, int num)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyDailyReset(ISession session, DailyResetPOD dailyReset)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyUnLockAvatarFrame(ISession session, int avatarFrame, bool remove)
        {
            //throw new System.NotImplementedException();
        }
        void CNetPlayer.SC_notifyUnLockTitle(ISession session, int title, bool remove)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyExecution(ISession session, int id)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyAvatarTimelimit(ISession session, Dictionary<int, int> avatarTimelimit)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyAvatarFrameTimelimit(ISession session, Dictionary<int, int> avatarFrameTimelimit)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_notifyTitleTimelimit(ISession session, Dictionary<int, int> titleTimelimit)
        {
            //throw new System.NotImplementedException();
        }

        void CNetPlayer.SC_updatePlayerInfo(ISession session, UpdatePlayerInfoPOD update)
        {
            //throw new NotImplementedException();
            this.UpdatePlayerInfo(update);
            PODPool<UpdatePlayerInfoPOD>.Put(update);
        }

        ISession CNetPlayer.GetSession()
        {
            return GameServerModule.Instance.CurrSession;
        }
    }
}
